import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsArray, IsBoolean, IsEnum, IsOptional, IsString, IsUUID, Min } from 'class-validator';
import { ContentStatus, ContentType } from '../../common/enums';

export class UserQueryContentDto {
  @ApiProperty({
    description: '根据内容标题进行模糊查询',
    required: false,
  })
  @IsString()
  @IsOptional()
  title?: string;

  @ApiProperty({
    description: '根据内容类型过滤',
    enum: ContentType,
    required: false,
  })
  @IsEnum(ContentType)
  @IsOptional()
  contentType?: ContentType;

  @ApiProperty({
    description: '根据模板 ID 查询内容',
    format: 'uuid',
    required: false,
  })
  @IsUUID()
  @IsOptional()
  templateId?: string;

  @ApiProperty({
    description: '内容状态过滤，支持多选（逗号分隔或数组）',
    enum: ContentStatus,
    isArray: true,
    example: 'self_created_approved,others_created_approved',
    required: false,
  })
  @IsOptional()
  @Transform(({ value }) => {
    if (typeof value === 'string') {
      return value.split(',').map((item) => item.trim());
    }
    return value;
  })
  @IsArray()
  @IsEnum(ContentStatus, { each: true })
  contentStatus?: ContentStatus[];

  @ApiProperty({
    description: '页码，从1开始',
    minimum: 1,
    default: 1,
    required: false,
  })
  @Type(() => Number)
  @Min(1)
  @IsOptional()
  page?: number = 1;

  @ApiProperty({
    description: '每页数量',
    minimum: 1,
    maximum: 100,
    default: 20,
    required: false,
  })
  @Type(() => Number)
  @Min(1)
  @IsOptional()
  pageSize?: number = 20;
}
